package com.hm.common.autoconfigure;

import com.hm.common.plugin.network.netty.NettyServerBootstrap;
import com.hm.common.plugin.oss.OssCloudBootstrap;
import com.hm.common.plugin.oss.qiniu.QiNiuCloudPlugin;
import com.hm.common.su.CommonDef;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shishun.wang
 * @version 1.0
 * @date 2019/4/2 17:16
 * @describe
 */
@Configuration
@ConditionalOnClass(QiNiuCloudPlugin.class)
@EnableConfigurationProperties(CommonProperties.class)
@ConditionalOnProperty(prefix = CommonDef.PROPERTIES_CONFIG_PREFIX, value = "enable", matchIfMissing = true)
public class CommonAutoConfiguration {

	@Autowired
	private CommonProperties commonProperties;

	@Bean
	@ConditionalOnMissingBean(OssCloudBootstrap.class)
	public OssCloudBootstrap ossCloudBootstrap(){
		return new OssCloudBootstrap(commonProperties);
	}
	
	@Bean
	@ConditionalOnMissingBean(NettyServerBootstrap.class)
	public NettyServerBootstrap nettyServerBootstrap(){
		return new NettyServerBootstrap(commonProperties);
	}
	
}
